package abg.core.common.util.valid.handler;


import abg.core.common.util.StringKit;
import abg.core.common.util.valid.Email;
import abg.core.common.util.valid.ValidKit;
import abg.core.common.util.valid.base.ValidBaseHandler;
import abg.core.domain.sys.ServiceException;
import org.springframework.stereotype.Component;

@Component
public class EmailHandler implements ValidBaseHandler<Email, String> {

    @Override
    public void valid(Email annotation, String paramName, String paramValue) {
        if (StringKit.isBlank(paramValue))
            throw new ServiceException(StringKit.blankDefStr(annotation.msg(), "参数：" + paramName + "，不能为空"));

        if (!ValidKit.email.check(paramValue)) {
            throw new ServiceException(StringKit.blankDefStr(annotation.msg(), "参数：" + paramName + "，非正确邮箱地址"));
        }

    }

}
